﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.Web.Configuration;
using System.Configuration;
using System.Security.Cryptography;


public partial class _Default : System.Web.UI.Page
{
    public DataTable DT;
    public cs_DataColnum.ParRegister Register;
    public static ConnectionStringSettings PersonialConnString = WebConfigurationManager.ConnectionStrings["TwniceFoodConnectionString"];
    protected void Page_Load(object sender, EventArgs e)
    {
          if(!Page.IsPostBack)
          {
            DataSet Ds = new DataSet();
            Ds = DataManager.FavoriteManager.Instance.GetFavorite();
            this.drop_Favorite.DataSource = Ds;
            this.drop_Favorite.DataBind();
          }
    }

    /// <summary>
    /// 判斷性別
    /// </summary>
    /// <returns></returns>
    protected string Sex()
    {
        if (chk_Man.Checked == true)
        {
          return  chk_Man.Text;
        }
        else
        {
          return  chk_WoMan.Text;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        System.Security.Cryptography.RNGCryptoServiceProvider rng =
        new System.Security.Cryptography.RNGCryptoServiceProvider();
        byte[] buf = new byte[15];
        rng.GetBytes(buf);
        string Salt = Convert.ToBase64String(buf);
        string Pwd= System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text.Trim() +Salt, "sha1");
        string AgaPwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(txtAgainPassword.Text.Trim() + Salt, "Sha1");

        try
        {
            DataManager.RegisterManager.Instance.InsertRecord(
                    txtUserName.Text.Trim(),
                    txtNickName.Text.Trim(),
                    Sex(),
                    Salt,
                   Pwd,
                    AgaPwd,
                    txtEmail.Text.Trim(), txtCellPhone.Text.Trim(),
                    txtBrithDay.Value.ToString(),
                   txt_Constellation.Text.Trim(), drop_Favorite.SelectedItem.ToString(),
                    DateTime.Now
                );
   
        }
        catch (Exception ex )
        {
            throw ex;
        }
     
    }
    protected void Button_Click(object sender, EventArgs e)
    { 

    }

    protected void Constellation(string BirthDay)
    {
        //星座判斷功能
        try
        {
            if (Convert.ToDateTime("0000/12/22".Substring(5, 5)) <= Convert.ToDateTime((this.txtBrithDay.Value).Substring(5, 5)) || Convert.ToDateTime("3999/01/19".Substring(5, 5)) >= Convert.ToDateTime((this.txtBrithDay.Value).Substring(5, 5)))
            {
                txt_Constellation.Text = "魔羯座";//    (12/22 - 1/19)    Capricorn
            }
            if (Convert.ToDateTime("0000/01/20".Substring(5, 5)) <= Convert.ToDateTime((this.txtBrithDay.Value).Substring(5, 5)) && Convert.ToDateTime("3999/02/18".Substring(5, 5)) >= Convert.ToDateTime((this.txtBrithDay.Value).Substring(5, 5)))
            {
                txt_Constellation.Text = "水瓶座";//   (1/20 - 2/18)     Aquarius
            }
            if (Convert.ToDateTime("0000/02/19".Substring(5, 5)) <= Convert.ToDateTime((this.txtBrithDay.Value).Substring(5, 5)) && Convert.ToDateTime("3999/03/20".Substring(5, 5)) >= Convert.ToDateTime((this.txtBrithDay.Value).Substring(5, 5)))
            {
                txt_Constellation.Text = "雙魚座";//   (2/19 - 3/20)     Pisces
            }
            if (Convert.ToDateTime("0000/03/21".Substring(5, 5)) <= Convert.ToDateTime((this.txtBrithDay.Value).Substring(5, 5)) && Convert.ToDateTime("3999/04/20".Substring(5, 5)) >= Convert.ToDateTime((this.txtBrithDay.Value).Substring(5, 5)))
            {
                txt_Constellation.Text = "牡羊座";//    (3/21 - 4/20)     Aries
            }
            if (Convert.ToDateTime("0000/04/21".Substring(5, 5)) <= Convert.ToDateTime((this.txtBrithDay.Value).Substring(5, 5)) && Convert.ToDateTime("3999/05/20".Substring(5, 5)) >= Convert.ToDateTime((this.txtBrithDay.Value).Substring(5, 5)))
            {
                txt_Constellation.Text = "金牛座";//    (4/21 - 5/20)     Taurus
            }
            if (Convert.ToDateTime("0000/05/21".Substring(5, 5)) <= Convert.ToDateTime((this.txtBrithDay.Value).Substring(5, 5)) && Convert.ToDateTime("3999/06/21".Substring(5, 5)) >= Convert.ToDateTime((this.txtBrithDay.Value).Substring(5, 5)))
            {
                txt_Constellation.Text = "雙子座";//    (5/21 - 6/21)     Gemini
            }
            if (Convert.ToDateTime("0000/06/22".Substring(5, 5)) <= Convert.ToDateTime((this.txtBrithDay.Value).Substring(5, 5)) && Convert.ToDateTime("3999/07/22".Substring(5, 5)) >= Convert.ToDateTime((this.txtBrithDay.Value).Substring(5, 5)))
            {
                txt_Constellation.Text = "巨蟹座";//    (6/22 - 7/22)     Cancer
            }
            if (Convert.ToDateTime("0000/07/23".Substring(5, 5)) <= Convert.ToDateTime((this.txtBrithDay.Value).Substring(5, 5)) && Convert.ToDateTime("3999/08/22".Substring(5, 5)) >= Convert.ToDateTime((this.txtBrithDay.Value).Substring(5, 5)))
            {
                txt_Constellation.Text = "獅子座";//    (7/23 - 8/22)     Leo
            }
            if (Convert.ToDateTime("0000/08/23".Substring(5, 5)) <= Convert.ToDateTime((this.txtBrithDay.Value).Substring(5, 5)) && Convert.ToDateTime("3999/09/22".Substring(5, 5)) >= Convert.ToDateTime((this.txtBrithDay.Value).Substring(5, 5)))
            {
                txt_Constellation.Text = "處女座";//    (8/23 - 9/22)     Virgo
            }
            if (Convert.ToDateTime("0000/09/23".Substring(5, 5)) <= Convert.ToDateTime((this.txtBrithDay.Value).Substring(5, 5)) && Convert.ToDateTime("3999/10/22".Substring(5, 5)) >= Convert.ToDateTime((this.txtBrithDay.Value).Substring(5, 5)))
            {
                txt_Constellation.Text = "天秤座";//    (9/23 - 10/22)    Libra
            }
            if (Convert.ToDateTime("0000/10/23".Substring(5, 5)) <= Convert.ToDateTime((this.txtBrithDay.Value).Substring(5, 5)) && Convert.ToDateTime("3999/11/21".Substring(5, 5)) >= Convert.ToDateTime((this.txtBrithDay.Value).Substring(5, 5)))
            {
                txt_Constellation.Text = "天蝎座";//    (10/23 - 11/21)   Scorpio
            }
            if (Convert.ToDateTime("0000/11/22".Substring(5, 5)) <= Convert.ToDateTime((this.txtBrithDay.Value).Substring(5, 5)) && Convert.ToDateTime("3999/12/21".Substring(5, 5)) >= Convert.ToDateTime((this.txtBrithDay.Value).Substring(5, 5)))
            {
                txt_Constellation.Text = "射手座";//    (11/22 - 12/21)   Sagittarius
            }
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('" + ex.Message.ToString() + "')</script>");
            Response.Write("<script>alert('請先選擇生日')</script>");
        }
    }

 
  
}